using Mapster;
using SmartCommunity.Models;
using System.ComponentModel.DataAnnotations;

namespace SmartCommunity.Services.Community
{
    #region DTO属性映射
    /// <summary>
    /// 属性映射 BuildingDtoRegister
    /// </summary>
    public class BuildingDtoRegister : IRegister
    {
        public void Register(TypeAdapterConfig config)
        {
            config.ForType<BuildingEntity, BuildingDto>()
                .Map(d => d.AreaName, s => s.Area.AreaName, s => s.Area != null)
                .Map(d => d.CommunityId, s => s.Area.CommunityId, s => s.Area != null)
                .Map(d => d.CommunityName, s => s.Area.CommunityName, s => s.Area != null)
                ;
        }
    }
    #endregion

    #region 数据传输对象 BuildingDto
    /// <summary>
    /// 数据传输对象：
    /// </summary>
    public class BuildingDto : BaseDto
    {
        /// <summary>
        /// 楼宇Id
        /// </summary>
        public Guid BuildingId { get; set; }

        /// <summary>
        /// 小区ID
        /// </summary>
        public Guid AreaId { get; set; }
        public Guid CommunityId { get; set; }
        public string? AreaName { get; set; }
        public string? CommunityName { get; set; }

        /// <summary>
        /// 上级id
        /// </summary>
        public Guid? ParentId { get; set; }

        /// <summary>
        /// 楼宇编号
        /// </summary>
        [Required(ErrorMessage = "楼宇编号不能为空")]
        [StringLength(20, ErrorMessage = "楼宇编号 长度不能超过 20.")]
        public string BuildingNo { get; set; } = string.Empty;

        /// <summary>
        /// 楼宇名称
        /// </summary>
        [Required(ErrorMessage = "楼宇名称不能为空")]
        [StringLength(50, ErrorMessage = "楼宇名称 长度不能超过 50.")]
        public string BuildingName { get; set; } = string.Empty;

        /// <summary>
        /// 房间用途
        /// </summary>
        public int BuildingUsage { get; set; }
        public int BuildingLevel { get; set; }

        /// <summary>
        /// 户型
        /// </summary>
        public int BuildingType { get; set; }

        /// <summary>
        /// 朝向
        /// </summary>
        public int BuildingDirection { get; set; }

        public string? BuildingLevelName { get; set; }
        public string? BuildingTypeName { get; set; }
        public string? BuildingUsageName { get; set; }
        public string? BuildingDirectionName { get; set; }

        /// <summary>
        /// 层数
        /// </summary>
        public int Floor { get; set; }

        /// <summary>
        /// 备注说明
        /// </summary>
        [StringLength(255, ErrorMessage = "备注说明 长度不能超过 255.")]
        public string? Remark { get; set; }

        public List<BuildingDto> Children { get; set; } = [];
        public string? Icon { get; set; }

    }
    #endregion

    #region 数据查询对象
    /// <summary>
    /// 查询模型：
    /// </summary>
    public class BuildingQuery : AbstractQuery<BuildingEntity>
    {
        /// <summary>
        /// 主键ID多选查询
        /// </summary>
        public IEnumerable<Guid> Ids { get; set; } = [];

        /// <summary>
        /// 根据查询条件添加查询表达式
        /// </summary>
        protected override void MergeQueryExpression()
        {
            AddExpression(Ids.Any(), e => Ids.Contains(e.BuildingId));
            AddSearchExpression(s => o => o.BuildingName.Contains(s));
        }
    }
    #endregion
}
